#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>


struct head
{
	int type;
	char mean[10];
};


struct user
{
	char name[10];
	char passwd[10];
};



int main()
{

	int sock = 0;
	int ret = 0;
	char buf[1024] = {0};

	struct sockaddr_in serAddr;
    memset(&serAddr,0,sizeof(serAddr));

	sock = socket(AF_INET,SOCK_DGRAM,0);
	if(sock == -1)
	{
		perror("sock");
		exit(-1);
	}

	serAddr.sin_family = AF_INET;
    serAddr.sin_port = 6868;
    serAddr.sin_addr.s_addr = inet_addr("192.168.0.156");


	struct head hd;
	memset(&hd,0,sizeof(hd));

	hd.type = 1;
	strcpy(hd.mean,"register");

	struct user us;
	memset(&us,0,sizeof(us));

	strcpy(us.name,"mike");
	strcpy(us.passwd,"123#");

	char msg[50] = {0};

	memcpy(msg,&hd,sizeof(struct head));
	memcpy(msg + sizeof(struct head),&us,sizeof(struct user));

    ret = sendto(sock,msg,sizeof(struct head) + sizeof(struct user),0,(struct sockaddr *)&serAddr,sizeof(struct sockaddr));
	if(ret == -1)
	{
		perror("sendto");
	}

	

	close(sock);

}

